package controller.converters.admin;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import model.vos.admin.Admin;
import controller.services.impl.admin.JsfAdminService;



public class AdminConverter implements Converter{
	
	public Object getAsObject(FacesContext context,
			UIComponent component, String value)
					throws ConverterException {
		if (value == null) {
			return null;
		}
		return new JsfAdminService()
		.pesquisarPorId(Long.parseLong(value));
	}
	
	public String getAsString(FacesContext context,
			UIComponent component, Object object)
					throws ConverterException {
		if (object == null) {
			return null;
		}
		Admin admin = (Admin) object;
		return admin.getId().toString();
	}

}
